#ifndef IRQDISPATCHER_H
#define IRQDISPATCHER_H

#include <Globals.h>
#include <Map.h>
#include <Process.h>
#include <Resource.h>
#include <ProcessManager.h>

/**
  Syscall interface.
**/
namespace IRQDispatcher_IF
{
  const int registerHandler  =0;
  const int unregisterHandler=1;
};

/**
  Dispatches interrupt requests as RPC calls, notifying processes.
**/
class IRQDispatcher : public Callable, public InterruptServiceRoutine
{
public:
  IRQDispatcher();

  ~IRQDispatcher();
  
  void registerHandler(int irq, u32int pid, int handlerIdx);
  
  void unregisterHandler(int irq, u32int pid);
  
  virtual void run(Registers *r);
  
  /**
    We are a system resource.
  **/
  Resource *resource;
  
private:
  /**
    Maps process IDs to handler indexes.
  **/
  typedef Map<Process *, int, 8> HandlerMap;
  /**
    One HandlerMap for each IRQ.
  **/
  HandlerMap *maps[16];
};

#endif
